<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <g-year-picker
                placeholder="请选择出版时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classess">
              <j-dict-select-tag type="list" v-model="model.classess" dictCode="YXJC_CLASSESS" placeholder="请选择级别" @change="getTotalScore"/>

            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item v-show="!(model.classess==1)" label="奖项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="award">
              <j-dict-select-tag type="list" v-model="model.award" dictCode="YXJC_AWARD" placeholder="请选择奖项"  @change="getTotalScore"/>

            </a-form-model-item>
          </a-col>
          <a-col :span="16" >
            <a-form-model-item label="教材名称" :labelCol="{span:3}" :wrapperCol="{span:20}" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入教材名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="totalScore">
              <a-input v-model="model.totalScore" placeholder="请输入名称" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="备注" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
<!--    <member-list ref="memberListRef" v-model="memberListTable.dataSource" :total-score="model.totalScore" :is-passed="model.isPass==1" :disabled="formDisabled" :loading="memberListTable.loading"></member-list>-->
    <member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model" :disabled="formDisabled" :loading="memberListTable.loading"></member-list>

  </a-spin>
</template>

<script>

import { getAction } from '@/api/manage'
import moment from 'moment'
import MemberList from '@views/gfxy/common/memberList'
import { GfxyYearRangePickerMixin } from '@/mixins/GfxyYearRangePickerMixin'
import GYearPicker from '@views/gfxy/common/GYearPicker'
import { GfxyMemberListMixin } from '@/mixins/GfxyMemberListMixin'


export default {
  name: 'TYxjcForm',
  mixins: [
    GfxyYearRangePickerMixin,
    GfxyMemberListMixin
  ],
  components: {
    MemberList,
    GYearPicker
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 },
      },

      validatorRules: {
        date: [
          { required: true, message: '请输入出版时间!'},
        ],
        award: [
          { required: true, message: '请输入奖项!'},
        ],
        classess: [
          { required: true, message: '请输入级别!'},
        ],

        projectName: [
          { required: true, message: '请输入教材名称!'},
        ],
      },

      url: {
        add: "/jin/tYxjc/add",
        edit: "/jin/tYxjc/edit",
        queryById: "/jin/tYxjc/queryById",
        getTotalScore: "/jin/tYxjc/getTotalScore",
        tMemberList: {
          list: '/jin/tYxjc/queryTMemberListByMainId'
        },
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    itemValue:{
      type: Number,
      required: true,
    },
    date:{
      type: String,
      required: true,
    }
  },
  computed: {
    formDisabled(){
      return this.disabled
    },
    // initwatch(){
    //   console.log(this.model.classess)
    //   if (this.model.classess==1){
    //     return false
    //   }else {
    //     return true
    //   }
    // },
  },
  created () {
  },
  methods: {
    // initwatch(){
    //   // console.log(this.model.classess)
    //   // if (this.model.classess==1){
    //   return false
    //   // }else {
    //   //   return true
    //   // }
    // },
    getTotalScore(){
      if (this.model.classess == 1){
        this.validatorRules.award[0].required = false
      }else {
        this.validatorRules.award[0].required = true
      }

      if(this.model.classess != undefined){
        this.confirmLoading = true;
        getAction(this.url.getTotalScore,{classess: this.model.classess, award: this.model.award}).then((res) => {
          if (res.success) {
            this.model.totalScore = res.result;
            this.$nextTick(()=>{
              this.$refs.memberListRef.getScore();
            })
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.confirmLoading = false;
        })
      }
    },
  }
}
</script>

<style scoped>
</style>
